package util

import (
	"context"
	"github.com/gogf/gf/v2/os/glog"
)

type Level uint8

const (
	DebugLevel Level = iota
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
	PanicLevel
	NoLevel
	Disabled
)

func init() {
	// 设置默认日志级别为Debug
	glog.SetLevel(glog.LEVEL_ALL)
}

func SetLevel(l Level) {
	switch l {
	case DebugLevel:
		glog.SetLevel(glog.LEVEL_ALL)
	case InfoLevel:
		glog.SetLevel(glog.LEVEL_INFO)
	case WarnLevel:
		glog.SetLevel(glog.LEVEL_WARN)
	case ErrorLevel:
		glog.SetLevel(glog.LEVEL_ERRO)
	case FatalLevel:
		glog.SetLevel(glog.LEVEL_FATA)
	case PanicLevel:
		glog.SetLevel(glog.LEVEL_PANI)
	case Disabled:
		glog.SetLevel(glog.LEVEL_NONE)
	}
}

func Infof(format string, v ...interface{}) {
	glog.Infof(context.Background(), format, v...)
}

func Debugf(format string, v ...interface{}) {
	glog.Debugf(context.Background(), format, v...)
}

func Warnf(format string, v ...interface{}) {
	glog.Warningf(context.Background(), format, v...)
}

func Errorf(format string, v ...interface{}) {
	glog.Errorf(context.Background(), format, v...)
}

func Panicf(format string, v ...interface{}) {
	glog.Panicf(context.Background(), format, v...)
}
